<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="gdufs.stat.service.FwtjQuery" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.Date" %>
<%@page import="java.text.*" %>

<%@page import="org.apache.commons.lang.StringUtils"%>
<html>
<head>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application); 
FwtjQuery fwtjQuery = (FwtjQuery)context.getBean("fwtjQuery");
%>
<%
	DecimalFormat dFormat = new DecimalFormat("##.##%");

	String weekStatics = fwtjQuery.getWeekStatics(null);

	String starttime = "";
	String endtime = "";
	String metier = "";
	metier = request.getParameter("metier");
	starttime = request.getParameter("starttime");
	endtime = request.getParameter("endtime");
	
	
	List<Map> deptVisitStatics = fwtjQuery.getDeptVisitStatics(metier,starttime,endtime);
	if(deptVisitStatics == null){
		deptVisitStatics = new ArrayList<Map>();
	}
	
	starttime = StringUtils.trimToEmpty(starttime);
	endtime = StringUtils.trimToEmpty(endtime);
%>

<script type="text/javascript">
	function weekStatics(){
		myChart.setXMLData("<%=weekStatics%>");
		myChart.render("chartContainer"); 
	}

	function monthStatics(){
		myChart.setXMLData("<%=fwtjQuery.getMonthStatics(null)%>");
		myChart.render("chartContainer");
	}
	
	function yearStatics(){
		myChart.setXMLData("<%=fwtjQuery.getYearStatics(null)%>");
		myChart.render("chartContainer");
	}

	function initSelect(){
		var metier = document.getElementById("metier");
		var value = "<%=metier%>";
		for(var i = 0 ; i < metier.options.length ; i++){
			var option = metier.options[i];
			if(option.value == value ){
				option.selected="selected";
				return;
			}
		}
	}

	function doReset(){
		document.getElementById("metier").selectedIndex = 0;
		document.getElementById("starttime").value = "";
		document.getElementById("endtime").value = "";
	}
 	
</script>
<%@include file="/inc/head.jsp" %>
<title>按部门统计登录情况</title>
<script type="text/javascript" src="../FusionCharts/FusionCharts.js"></script>
<link href="../css/calendar.css" rel="stylesheet" type="text/css">
<script language=javascript src="../javascripts/calendar/calendar.js"></script>
<script language=javascript src="../javascripts/calendar/calendar-zh.js"></script>
<script language=javascript src="../javascripts/calendar/calendar-setup.js"></script>
</head>
<body onload="initSelect();" style="margin: 5px;"> 
		<table cellpadding="5" cellspacing="0" border="0" bordercolor="#aaa" style="border:1px solid #aaa">
			<tr>
				<td><a href="#" onclick="weekStatics();return false;">按周统计</a></td>
				<td><a href="#" onclick="monthStatics();return;">按月统计</a></td>
				<td><a href="#" onclick="yearStatics();return;">按年统计<a/></td>
			</tr>
		</table>
		<div id="chartContainer" style="float:none;">FusionCharts will load here!</div>
		<script type="text/javascript">
			var myChart = new FusionCharts( "../FusionCharts/Column3D.swf","myChartId", "100%", "400px", "0", "1" );  
			myChart.setXMLData("<%=weekStatics%>");   
			myChart.render("chartContainer");        
		</script>
	
	
	<!-- 列表统计 -->
	<form action="deptStatics.jsp" method="post">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding:5px;border:1px solid #aaaaaa;background-color: #efefef">
			<tr>
				<td align="right">用户类别:</td>
				<td><select id="metier" name="metier" style="background-color: white;">
					<option value="0">所有用户</option>
					<option value="1">教师</option>
					<option value="2">研究生</option>
					<option value="1">本科生</option>
				</select></td>
				<td align="right">开始时间:</td>
				<td><input type="text" id="starttime" name="starttime" value="<%=starttime %>">&nbsp;<input name="_starttime" type="image" src="../images/iconDate.gif" id="_starttime"></td>
				<td align="right">结束时间:</td>
				<td><input type="text" id="endtime" name="endtime" value="<%=endtime %>">&nbsp;<input name="_endtime" type="image" src="../images/iconDate.gif" id="_endtime"></td>
				<td><input type="submit" value="提交" />&nbsp;<input type="button" onclick="doReset();"
					value="重置"></td>
			</tr>
		</table>
		
		<table cellpadding="3" cellspacing="0" width="100%" border="1" style="border:1px solid #aaaaaa;border-collapse: collapse;margin-top: 5px;" bordercolor="#aaaaaa">
			<tr >
				<th width="30%">部门名称</th>
				<th width="20%">访问人数</th>
				<th width="20%">访问次数</th>
				<th width="30%">该部门访问次数占总次数百分比</th>
			</tr>
			<% 
				for(int i = 0 ; i < deptVisitStatics.size() ; i++){
					Map staticsMap = (Map)deptVisitStatics.get(i);
					String deptcode = (String)staticsMap.get("deptcode");
					String deptname = (String)staticsMap.get("deptname");
					if(deptname == null || "".equals(deptname) || "null".equals(deptname)){
						deptname = "所有";
					}
					String userAccount = (String)staticsMap.get("userAccount");
					int visitAccount = (Integer)staticsMap.get("visitAccount");
					double percentage = (Double)staticsMap.get("percentage");
			%>
				<tr>
					<!-- <td><a href="/fwtj/deptStaticsList.jsp?deptCode=<%=deptcode %>&metier=<%=metier %>&starttime=<%=starttime %>&endtime=<%=endtime %>"><%=deptname %></a></td> -->
					<td><%=deptname %></td>
					<td align="center"><%=userAccount %></td>
					<td align="center"><%=visitAccount %></td>
					<td align="center"><%=dFormat.format(percentage) %></td>
				</tr>
			<% 
				}
			%>
		</table>
		
	</form>

<script type=text/javascript>
		Calendar.setup(
		{
			inputField  : "starttime",	// 接受输入值的控件
			button      : "_starttime",	// 调用日历的控件
			ifFormat    : "%Y-%m-%d"	// 日期格式
		}		
		);
		
		Calendar.setup(
		{
			inputField  : "endtime",	// 接受输入值的控件
			button      : "_endtime",	// 调用日历的控件
			ifFormat    : "%Y-%m-%d"	// 日期格式
		}		
		);
				
</script>
</body>
</html>